package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.service.ShoppingCartService;
import com.sky.web.controller.BaseController;
import com.sky.web.domain.AjaxResult;
import com.sky.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author tzl
 * @Date 2023-07-23 11:37:01  星期日
 * @Description: TODO
 */
@Slf4j
@Api(tags = "微信客户端用户购物车接口")
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController extends BaseController {


    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 查询用户购物车信息
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "用户查询购物车")
    public AjaxResult list(){
        List<ShoppingCart> list = shoppingCartService.selectShoppingCart();
        return AjaxResult.success(list);
    }


    /**
     * 用户添加购物车
     * @param dto 商品信息
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "用户添加购物车")
    public AjaxResult add(@RequestBody ShoppingCartDTO dto){
        log.info("添加购物车，商品信息为：{}",dto);
        return toAjax(shoppingCartService.insertShoppingCart(dto));
    }

    /**
     * 用户修改购物车
     * @return
     */
    @PostMapping("/sub")
    @ApiOperation(value = "用户修改购物车")
    public AjaxResult sub(@RequestBody ShoppingCartDTO dto){
        return toAjax(shoppingCartService.updateShoppingCart(dto));
    }

    /**
     * 用户清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation(value = "用户清空购物车")
    public AjaxResult clean(){
        return toAjax(shoppingCartService.deleteShoppingCart());
    }
}
